package com.extension.company.presenter.my;

import com.extension.company.common.mvp.BasePresenter;
import com.extension.company.contract.AddressListAddContract;
import com.extension.company.model.my.AddressListAddMode;

import java.util.HashMap;

public class AddressListAddPresenter extends BasePresenter<AddressListAddMode, AddressListAddContract.View> {

	@Override
	public AddressListAddMode createModel() {
		return new AddressListAddMode();
	}

	@Override
	protected void onViewDestroy() {

	}

	/**
	 * 添加收货地址
	 *
	 * @param sign        标识
	 * @param token       token
	 * @param name        收货人姓名
	 * @param phone       收货人的手机号
	 * @param province_id 收货人的 省份
	 * @param city_id     收货人的 城市
	 * @param region_id   收货人的区域
	 * @param detail      收货的人的详情地址
	 * @param is_default  是否是默认地址
	 */
	public void saveAddress(String sign, String token, String name, String phone, String province_id, String city_id, String region_id, String detail, String is_default) {

		HashMap<String, String> map = new HashMap<>();
		map.put("sign", sign);
		map.put("token", token);
		map.put("name", name);
		map.put("phone", phone);
		map.put("province_id", province_id);
		map.put("city_id", city_id);
		map.put("region_id", region_id);
		map.put("detail", detail);
		map.put("is_default", is_default);

		model.saveAddressRequest(map, new AddressListAddContract.RequestCallback() {

			@Override
			public void showLoading() {
				if (null != getView()) {
					getView().showLoading();
				}

			}

			@Override
			public void hideLoading() {

			}

			@Override
			public void callbackSuccss(String msg) {
				if (null != getView()) {
					getView().addAddressBackSuccess(msg);
				}


			}

			@Override
			public void callbackFaile(String msg) {
				if (null != getView()) {
					getView().addAddressBackFaile(msg);
				}
			}
		});
	}

	/**
	 * 添加收货地址
	 *
	 * @param sign        标识
	 * @param token       token
	 * @param id          记录的id
	 * @param name        收货人姓名
	 * @param phone       收货人的手机号
	 * @param province_id 收货人的 省份
	 * @param city_id     收货人的 城市
	 * @param region_id   收货人的区域
	 * @param detail      收货的人的详情地址
	 * @param is_default  是否是默认地址
	 */
	public void editAddress(String sign, String token, String id, String name, String phone, String province_id, String city_id, String region_id, String detail, String is_default) {

		HashMap<String, String> map = new HashMap<>();
		map.put("sign", sign);
		map.put("token", token);
		map.put("id", id);
		map.put("name", name);
		map.put("phone", phone);
		map.put("province_id", province_id);
		map.put("city_id", city_id);
		map.put("region_id", region_id);
		map.put("detail", detail);
		map.put("is_default", is_default);

		model.editAddressRequest(map, new AddressListAddContract.RequestCallback() {

			@Override
			public void showLoading() {

			}

			@Override
			public void hideLoading() {

			}

			@Override
			public void callbackSuccss(String msg) {
				if (null != getView()) {
					getView().addAddressBackSuccess(msg);
				}


			}

			@Override
			public void callbackFaile(String msg) {

			}
		});
	}

}
